package com.tllq.zhongkang.controller;

import com.tllq.zhongkang.entity.ResultMap;
import com.tllq.zhongkang.service.IsiderService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@Slf4j
public class InsiderController {

    Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    IsiderService isiderService;

    @GetMapping("/member-info")
    public ResultMap findByMobile(String mobile){
        logger.info("/member-info参数：{} ",mobile);
        if (StringUtils.isEmpty(mobile)){
            ResultMap res = ResultMap.error("参数不能为空");
            logger.info("/member-info返回数据：{}",res);
            return res;
        }
        List<Map<String, String>> cardNos = isiderService.findBymobile(mobile);
        ResultMap res = ResultMap.ok(cardNos);
        logger.info("/member-info返回数据：{}",res);
        return res;
    }

    @GetMapping("/member")
    public ResultMap findByid(Integer cardNo){
        logger.info("/member参数：{}",cardNo);
        if (StringUtils.isEmpty(cardNo)){
            return ResultMap.error("参数不能为空");
        }
        Map<String, String> mbers = isiderService.findById(cardNo);
        return ResultMap.ok(mbers);
    }
}
